package mirrormonkey.core.module;

import mirrormonkey.core.messages.TimeSyncRequestMessage;
import mirrormonkey.core.messages.TimeSyncResponseMessage;
import mirrormonkey.framework.SyncAppState;

import com.jme3.network.Message;
import com.jme3.network.MessageConnection;
import com.jme3.network.MessageListener;

public class TimeSyncRequestListener implements
		MessageListener<MessageConnection> {

	public final SyncAppState appState;

	public TimeSyncRequestListener(SyncAppState appState) {
		this.appState = appState;
	}

	@Override
	public void messageReceived(MessageConnection source, Message m) {
		TimeSyncRequestMessage r = (TimeSyncRequestMessage) m;
		source.send(new TimeSyncResponseMessage(r.id, appState.getSyncTime()));
	}

}
